package objects;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 
 * @author stephenbwilliamson
 */
public class Gene {

	private String name;
	private String source;
	private String gffItemType;
	private ValidPosition bounds;
	private char strand;
	private Chromosome parent;
	private List<Transcript> transcripts;
	private HashMap<Integer, Treatment> treatments;

	public Gene(String featureID, String source, String gffItemType, int start,
			int end, char strand, String parent) {
		this.name = featureID;
		this.source = source;
		this.gffItemType = gffItemType;
		this.bounds = new ValidPosition(start, end);
		this.strand = strand;
		this.parent = Chromosome.getChromosome(parent);
		treatments = new HashMap<Integer, Treatment>();
		transcripts = new ArrayList<Transcript>();
	}

	public void addTranscript(Transcript t) {
		transcripts.add(t);
	}

	public List<Transcript> getTranscripts() {
		return transcripts;
	}

	public void addTreatment(Treatment t) {
		treatments.put(t.getTreatmentID(), t);
	}

	public Treatment getTreatmentByID(int id) {
		return treatments.get(id);
	}

	public List<Treatment> getTreatments(List<Integer> treatList) {
		List<Treatment> t = new ArrayList<Treatment>();
		for (Integer id : treatList) {
			if (treatments.containsKey(id))
				t.add(treatments.get(id));
		}
		return t;
	}

	public List<Treatment> getTreatmentList() {
		return new ArrayList<Treatment>(treatments.values());
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getItemType() {
		return gffItemType;
	}

	public int getStartPosition() {
		return bounds.start;
	}

	public int getEndPosition() {
		return bounds.end;
	}

	public ValidPosition getValidPosition() {
		return bounds;
	}

	public int getValidDistance() {
		return bounds.getDistance();
	}

	public char getStrand() {
		return strand;
	}

	public Chromosome getParentChromosome() {
		return parent;
	}

	public void setParentChromosome(Chromosome parent) {
		this.parent = parent;
	}

	@Override
	public String toString() {
		return name;
	}

}
